package ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.wb.swt.SWTResourceManager;


public class TabFolderItem extends Label implements  MouseListener{

	private Composite view;
	private TabFolder parent;
	public TabFolderItem(Composite parent, Composite view) {
		super(parent, SWT.NONE);
		this.view = view;
		this.parent = (TabFolder) parent;
		setSize(64, getParent().getSize().y);
		setAlignment(SWT.CENTER);
		this.addMouseListener(this);
		
	}
	
	public void active() {
		parent.setCurrentTabFolderItem(this);
		setForeground(parent.getDefaultColor());
		//TODO 美化 加下划线
//		GC gc = new GC(this);
//		gc.setForeground(parent.getDefaultColor());
//		gc.setLineWidth(6);
//		int y = parent.getSize().y - 15;
//		gc.drawLine(16, y, 48, y);
//		gc.dispose();
		if (view != null) {
			view.setVisible(true);
		}
	}
	
	public void setView(Composite view) {
		this.view = view;
	}
	
	public void deactive() {
		setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		//redraw();
		if (view != null) {
			view.setVisible(false);
		}
	}

	@Override
	public void mouseDoubleClick(MouseEvent e) {}

	@Override
	public void mouseDown(MouseEvent e) {}

	@Override
	public void mouseUp(MouseEvent e) {
		TabFolderItem currentTabFolderItem = parent.getCurrentTabFolderItem();
		if (currentTabFolderItem != null) {
			currentTabFolderItem.deactive();
		}
		active();
	}
	@Override
	protected void checkSubclass() {
	}
}
